(function() {
	var app = angular.module('processMonitorApp', [ 'ui.bootstrap' ]);
	app
			.controller(
					'processMonitorController',
					function($http,$scope, $log, $uibModal) {
						var basePath = $scope.getAppBasePath();
						$scope.insertComponent = {};
						$scope.deleteComponent = {};
						var controller = this;
						controller.parameter = {};
						controller.queryParameter = "";
						this.warningConfigList = [];
						this.indexList = [];
//						$scope.processUrl="http://10.7.83.67:8880";
						this.queryCondition = {					
							"ipIndex":"",
							"page" : 1,
							"pageSize" : 5,
						};
						this.paginationInfo = {
							"maxSize" : 5,
							"totalPages" : 0,
							"totalElements" : 0
						};

						$scope.clickEvent = function() {
							controller.queryCondition.page = controller.queryCondition.forwordPage;
							loadData();
						}

						// 跳转页数，回车事件
						$scope.enterEvent = function(e) {
							var keycode = window.event ? e.keyCode : e.which;
							if (keycode == 13) {
								$scope.clickEvent();
							}
						}

						this.pageChanged = function() {
							loadData();
						}
						// 完成全选全部选事件
						$("#check_all").click(
								function() {
									$(".check_item").prop("checked",
											$(this).prop("checked"));
								});
						// 选中单个元素，如果单个元素选择满了，那么第一个主元素也被选中
						$(document)
								.on(
										"click",
										".check_item",
										function() {
											if ($(".check_item:checked").length == $(".check_item").length) {
												$("#check_all").prop("checked",
														true);
											}
											if ($(".check_item:checked").length == 0) {
												$("#check_all").prop("checked",
														false);
											}
										});
						
						//查看进程详情
						this.ckeckProcessInfo=function(data){
							console.log(data.type);
							var modalInstanceUpdate = $uibModal
									.open({
										backdrop : 'static',
										keyboard : false,
										scope : $scope,
										// animation :
										// $scope.animationsEnabled,// 打开时的动画开关
										templateUrl : 'js/controller/view.display/checkProcessMonitor.html',// 模态框的页面内容,这里的url是可以自己定义的,也就意味着什么都可以写
										controller : 'checkProcessController',// 这是模态框的控制器,是用来控制模态框的
										ariaLabelledBy : 'modal-title',
										ariaDescribedBy : 'modal-body',
									// size : "lg",// 模态框的大小尺寸
									});
							
							
							modalInstanceUpdate.opened.then(function(){//模态窗口打开之后执行的函数  
								 $.ajax({
									 type : "POST",
									 dataType : "json",
									 url : basePath+ "/data/getProcessConfig",
									 data:{
											"ip":data.ip,
											"port":data.command,
											"type":data.type
										},									
									 success : function(res) {		
										
										 var resultJson = angular.fromJson(res);
										 console.log(resultJson);
										 if(resultJson.length != 0){
											 $scope.showDetailprocessList={
													 "ip":resultJson[0].ip,
													 "pid":resultJson[0].pid,
													 "用户":resultJson[0].user,
													 "端口号":resultJson[0].port,
													 "CPU使用率":resultJson[0].cpuUse,
													 "开始时间":resultJson[0].startTime,
													 "内存使用率":resultJson[0].memoryUse,
													 "cmd":resultJson[0].cmd,
											 }
										 }
									 
									 
									 //手动刷新
									 	$scope.$apply();  
									 },errro:function(){
										 console.log("请求错误！")
									 }
									 });
			            
							}); 
							modalInstanceUpdate.result.then(function(result) {
								loadData();
							});
						}
						//查看进程详情
						this.ckeckProcessfuwu=function(data){
							console.log(data.type);
							var modalInstanceUpdate = $uibModal
									.open({
										backdrop : 'static',
										keyboard : false,
										scope : $scope,
										// animation :
										// $scope.animationsEnabled,// 打开时的动画开关
										templateUrl : 'js/controller/view.display/checkServeMonitor.html',// 模态框的页面内容,这里的url是可以自己定义的,也就意味着什么都可以写
										controller : 'checkProcessController',// 这是模态框的控制器,是用来控制模态框的
										ariaLabelledBy : 'modal-title',
										ariaDescribedBy : 'modal-body',
									// size : "lg",// 模态框的大小尺寸
									});
							
							
							modalInstanceUpdate.opened.then(function(){//模态窗口打开之后执行的函数  
								$.ajax({
									 type : "POST",
									 dataType : "json",
									 url : basePath+ "/data/getProcessConfig",
									 data:{
											"ip":data.ip,
											"port":data.command,
											"type":data.type
										},									
									 success : function(res) {		
										 var datapro=res.split("/n");
										 var str="";
										 for(var i=0;i<datapro.length;i++){
											 str="<p>"+datapro[i]+"</p>"
											 $("#severShow").append(str);
										 }
									
									 //手动刷新
									 	$scope.$apply();  
									 },errro:function(){
										 console.log("请求错误！")
									 }
									 });
			            
							}); 
							modalInstanceUpdate.result.then(function(result) {
								loadData();
							});
						}
						
						//查看IP详情
						this.ckeckIPInfo=function(data){
							console.log(data.hostid);
							var modalInstanceUpdate = $uibModal
									.open({
										backdrop : 'static',
										keyboard : false,
										scope : $scope,
										// animation :
										// $scope.animationsEnabled,// 打开时的动画开关
										templateUrl : 'js/controller/view.display/checkprocessIPMonitor.html',// 模态框的页面内容,这里的url是可以自己定义的,也就意味着什么都可以写
										controller : 'checkProcessIPController',// 这是模态框的控制器,是用来控制模态框的
										ariaLabelledBy : 'modal-title',
										ariaDescribedBy : 'modal-body',
									// size : "lg",// 模态框的大小尺寸
									});
							var emp=[];
							emp[0]={
									"hostid":data.hostid
									};
							modalInstanceUpdate.opened.then(function(){//模态窗口打开之后执行的函数  
								 $.ajax({
									 type : "POST",
									 dataType : "json",
									 url :basePath+ "/data/selectHostInfo",
									 contentType : 'application/json;charset=utf-8',//指定为json类型 
									 data : JSON.stringify(emp[0]),								
									 success : function(res) {	
										 var resultJson = angular
											.fromJson(res);
//										 console.log(resultJson);
									 $scope.showDetailprocessIPList={
											 "系统名称":resultJson[0].systemName,
											 "所属应用系统": resultJson[0].belongAppliedSystem,
											 "主机名": resultJson[0].hostName, 
											 "主机序列号":resultJson[0].hostSequenceNumber, 
											 "主机用途": resultJson[0].hostToUse, 
											 "ip": resultJson[0].ip,
											 "MAC":resultJson[0].mac,
											 "维护责任部门":resultJson[0].maintenanceResponsibleDepartment,
											 "维护责任人":resultJson[0].maintenanceResponsiblePerson,
											 "使用责任":resultJson[0].useResponsibility,
											 "维护责任部门":resultJson[0].useResponsibilityDepartment,
									
										 
									 }
									 console.log($scope.showDetailprocessIPList);	
									 //手动刷新
									 	$scope.$apply();  
									 },errro:function(){
										 console.log("请求错误！")
									 }
									 });
			            
							}); 
							modalInstanceUpdate.result.then(function(result) {
								loadData();
							});
						}
						
						// 新增配置
						this.insertConfig = function() {
							
							$scope.insertComponent = {};
							var modalInstanceAdd = $uibModal
									.open({
										backdrop : 'static',
										keyboard : false,
										scope : $scope,
										// animation :
										// $scope.animationsEnabled,// 打开时的动画开关
										templateUrl : 'js/controller/view.display/insertProcessMonitor.html',// 模态框的页面内容,这里的url是可以自己定义的,也就意味着什么都可以写
										controller : 'insertprocessMonitorController',// 这是模态框的控制器,是用来控制模态框的
										ariaLabelledBy : 'modal-title',
										ariaDescribedBy : 'modal-body',
									// size : "lg",// 模态框的大小尺寸
									});
							
							modalInstanceAdd.opened.then(function(){//模态窗口打开之后执行的函数  
								//加载ip树
								getTreeData(2,[]);
								//告警次数阈值下拉框获取
								   $scope.moSites = [
								                        {id :"5",name : "5次"},
								                        {id :"15",name : "15次"},
										        	    {id :"20",name : "20次"},
										        	    {id :"25",name : "25次"},
										        	    {id :"30",name : "30次"},
										        	    {id :"35",name : "35次"},
										        	    {id :"40",name : "40次"},
										        	    {id :"45",name : "45次"},
										        	    {id :"50",name : "50次"},
										        	    {id :"55",name : "55次"},
										        	    {id :"60",name : "60次"}
								           	];
						    //超阈值告警频率下拉框支获取
							   $scope.sixSites = [
							                        {id : "5", name : "5分钟"},
							                        {id : "15", name : "15分钟"},
									        	    {id : "20", name : "20分钟"},
									        	    {id : "25", name : "25分钟"},
									        	    {id : "30", name : "30分钟"},
									        	    {id : "35", name : "35分钟"},
									        	    {id : "40", name : "40分钟"},
									        	    {id : "45", name : "45分钟"},
									        	    {id : "50", name : "50分钟"},
									        	    {id : "55", name : "55分钟"},
									        	    {id : "60", name : "60分钟"}
							           	];
							  
							}); 

							modalInstanceAdd.result.then(function(result) {
								loadData();
							});
						}
						// 编辑配置
						this.updateConfig = function() {
							var conditons =  new Array();
							var ids = "";
							var id = "";  
	                        var hostid="";
	                        var port="";
							$.each($(".check_item:checked"), function() {
								
								id = $(this).parents("tr").find("td:eq(1)").text();
								hostid = $(this).parents("tr").find("td:eq(2)").text();
								conditons.push(id);
								
							})
							if(conditons == ""){
								alert("请勾选需要编辑的配置");
								return;
							}else if(conditons.length > 1){
								alert("只能选中一个进行配置");
								return;
							}else{
								 
								$scope.editdata = {};
								var modalInstanceAdd = $uibModal
										.open({
											backdrop : 'static',
											keyboard : false,
											scope : $scope,
											// animation :
											// $scope.animationsEnabled,// 打开时的动画开关
											templateUrl : 'js/controller/view.display/updateProcessMonitor.html',// 模态框的页面内容,这里的url是可以自己定义的,也就意味着什么都可以写
											controller : 'updateProcessController',// 这是模态框的控制器,是用来控制模态框的
											ariaLabelledBy : 'modal-title',
											ariaDescribedBy : 'modal-body',
										// size : "lg",// 模态框的大小尺寸
										});
								modalInstanceAdd.opened.then(function(){//模态窗口打开之后执行的函数  
									//告警次数阈值下拉框获取
									   $scope.moSites = [
									                        {id :"5",name : "5次"},
									                        {id :"15",name : "15次"},
											        	    {id :"20",name : "20次"},
											        	    {id :"25",name : "25次"},
											        	    {id :"30",name : "30次"},
											        	    {id :"35",name : "35次"},
											        	    {id :"40",name : "40次"},
											        	    {id :"45",name : "45次"},
											        	    {id :"50",name : "50次"},
											        	    {id :"55",name : "55次"},
											        	    {id :"60",name : "60次"}
									           	];
							    //超阈值告警频率下拉框支获取
								   $scope.sixSites = [
								                        {id : "5", name : "5分钟"},
								                        {id : "15", name : "15分钟"},
										        	    {id : "20", name : "20分钟"},
										        	    {id : "25", name : "25分钟"},
										        	    {id : "30", name : "30分钟"},
										        	    {id : "35", name : "35分钟"},
										        	    {id : "40", name : "40分钟"},
										        	    {id : "45", name : "45分钟"},
										        	    {id : "50", name : "50分钟"},
										        	    {id : "55", name : "55分钟"},
										        	    {id : "60", name : "60分钟"}
								           	];
								  
								
									 $.ajax({
										 type : "get",
										 dataType : "json",
										 url :basePath+ "/data/getProcessAll?ip=",
										 success : function(res) {
											 var resultJson = angular
												.fromJson(res);
											 console.log(resultJson);
											
										 for(var i=0;i<resultJson.length;i++){
											 if(id==resultJson[i].id){
												 $scope.id=resultJson[i].id;
												 $scope.command=resultJson[i].command;
												 $scope.desc=resultJson[i].desc;
												 $scope.type=resultJson[i].type;
												 $scope.purpose=resultJson[i].purpose;
												 $scope.ip=resultJson[i].ip;
												 $scope.hostid=resultJson[i].hostid;
												 $scope.status=resultJson[i].status;
											 }
										 }
//										 controller.paginationInfo.totalPages = 20;
//										 controller.paginationInfo.totalElements =10;
										 //手动刷新
										 	$scope.$apply();  
										 },errro:function(){
											 console.log("请求错误！")
										 }
										 });
//									//加载ip树
//									getTreeData(1,data);
					          	});  
								modalInstanceAdd.result.then(function(result) {
									loadData();
								});
			
							}
							
						}
						//删除配置
						this.deleteConfig = function() {
							var id="";
							var hostid="";
							var emp=[];
							var empObjList=[];
							$.each($(".check_item:checked"), function() {
								id = $(this).parents("tr").find("td:eq(1)").text();
								hostid = $(this).parents("tr").find("td:eq(2)").text();
								emp[0]={
									"id":id,
								};
								
								empObjList.push(emp[0]);
								
							})
							console.log( JSON.stringify(empObjList));
							// 如果没有选中的话
							if (id == "") {
								alert("请勾选需要删除的配置");
								return;
							} else {
							
								if (confirm("确认删除该的配置吗?")) {
									// 保存后台调用
									$.ajax({
												type : "POST",
												url : basePath+ "/data/deleteProcess",
												dataType : "json",
												contentType : 'application/json;charset=utf-8',//指定为json类型 
												data:JSON.stringify(empObjList),
												success : function(data) {
													alert("删除成功");
													loadData();
												}
											});

								}
							}
						}
						
						
						// 搜索事件
						this.search = function() {
							loadData();
						}

						// 重置事件
						this.reset = function() {
							this.queryCondition = {
									"ipIndex":"",
									"page" : 1,
									"pageSize" : 5,
								};
						}
						
						// 程序初期化
						this.init = function() {
							loadData();
							
						}
						this.init();

						// 加载数据
						function loadData() {
							if ($(".check_item:checked").length == 0) {
								$("#check_all").prop("checked", false);
							}
							
							// 参数获取
							var ip= controller.queryCondition.ipIndex;
							var page = controller.queryCondition.page;
							var pageSize = controller.queryCondition.pageSize;
//							console.log(ip);
							// 后台调用
							 $.ajax({
							 type : "get",
							 dataType : "json",
							 url :basePath+ "/data/getProcessAll?ip="+ip,
							
							 success : function(res) {
								 var resultJson = angular
									.fromJson(res);
								 console.log(resultJson);
								
							 controller.processConfigList =resultJson;
							 for(var i=0;i<res.length;i++){
//								 controller.searchConfigList =res[i].ip;
//								 console.log(res[i].ip);
							 }
//							 controller.paginationInfo.totalPages = 20;
//							 controller.paginationInfo.totalElements =10;
							 //手动刷新
							 	$scope.$apply();  
							 },errro:function(){
								 console.log("请求错误！")
							 }
							 });

						}
						
						// 获取树状图数据
						function getTreeData(type,data) { //1:选择ip弹窗  2：新增弹窗
							selectedMap=data.ipMap;
							selectedHostidsDb=[];
							selectedNames=[];
							tdInputId=data.id;
							for(var key in selectedMap){
								selectedHostidsDb.push(parseInt(key));
								selectedNames.push(selectedMap[key]);
							}
						
							var basePath = $scope.getAppBasePath();
							var address = "";
							$
									.ajax({
										type : "POST",
										url : basePath + "/data/getIpTreeData",
										dataType : "json",
										contentType : "application/json",
										success : function(data) {
											var resultArrary = JSON.parse(data);

											var setting = {
												// 异步加载POST方法
												async : {
													enable : true,
													contentType : "application/json",
													dataType : "text",
													type : "post",
													url : basePath
															+ "/data/asyncGetIpTreeData",
													autoParam : [ "commentId" ],
													otherParam : [
															"hostId",-1														],
													dataFilter : ajaxDataFilter
												},
												// checkBox 效果
												check : {
													enable : true,
													chkStyle : "checkbox"
												},
												callback : {
													onAsyncSuccess : zTreeOnAsyncSuccess,
													onClick : zTreeOnClick,
													onExpand : zTreeOnExpand,// 点击节点前+号加载
													onCheck : zTreeOnCheck// 点击chckBox框加载
												},
											};

											function zTreeOnAsyncSuccess() {
											}
											// checked box 选中 取消时候，ip值的状态设置
											function zTreeOnCheck(event,
													treeId, treeNode) {
											}
											function zTreeBeforeAsync(treeId,
													treeNode) {
												return (treeNode.isParent == true);
											}
											;
											// 返回数据转成json
											function ajaxDataFilter(treeId,parentNode, responseData) {
												responseData = JSON.parse(responseData);
												// 获取已经被配置的Ip，并且设置checked为true
												
												for (var i = 0; i < responseData.length; i++) {
													for(var key in selectedMap){
														if (parseInt(responseData[i].id) ==parseInt(key)) {
																$scope.controller.selectedIpByDbOldEmp.push(responseData[i]);
																responseData[i].checked = "true";
														}
													}
												}

												return responseData;
											};
											if(type==1){
												var zTreeObj = $.fn.zTree.init(
														$("#selectIP"), setting,
														resultArrary);
												//默认展开根目录
												$("#selectIP_1_switch").click();
												
												//选中已经配置过的ips
												var treeObj = $.fn.zTree.getZTreeObj("selectIP");
												var tempArray=selectedNames;
												tempArray=arrayRemoveRepeat(tempArray);//去重
												for(var i=0;i<tempArray.length;i++){
													var node = treeObj.getNodeByParam("name", tempArray[i], null).tId+"_switch";//根据name属性获取树结构节点 tId
													//拿到节点后点击“+"调用异步加载方法
													$("#"+node).click();
												}
												
											}else{
												var zTreeObj = $.fn.zTree.init($("#warningSelectIP"), setting,resultArrary);
									
											}
			
											$scope.zTreeObjNew = zTreeObj;
							
											function zTreeOnExpand(event,
													treeId, treeNode) {
												var nodes = zTreeObj
														.getSelectedNodes();
												if (nodes.length > 0
														&& treeNode.level != 0
														&& treeNode.level != 1) {
													zTreeObj
															.reAsyncChildNodes(
																	nodes[0],
																	"refresh");
												}
											}
											function zTreeOnClick(event,
													treeId, treeNode) {
											}

											// 过滤ztree显示数据
											var hiddenNodes;
											function filter() {
												// 显示上次搜索后背隐藏的结点
												zTreeObj.showNodes(hiddenNodes);
												var _keywords = $("#keyword")
														.val();
												if (_keywords == null
														|| _keywords == "") {
													zTreeObj
															.showNodes(hiddenNodes);
												} else {
													var nodes = zTreeObj
															.getNodesByParamFuzzy(
																	"name",
																	_keywords,
																	null); // 根据节点数据的属性搜索，获取条件模糊匹配的节点数据
																			// JSON
																			// 对象集合,(keywords)模糊匹配只能针对
																			// String
																			// 类型的数据
													if (nodes.length > 0) {
														zTreeObj.selectNode(nodes[0]); // 会让节点自动滚到到可视区域内
													}

													// 查找不符合条件的叶子节点
													function filterFunc(node) {
														var _keywords = $(
																"#keyword")
																.val();
														if (node.isParent
																|| node.name
																		.indexOf(_keywords) != -1) {
															return false;
														} else {
															return true;
														}
													}
													;

													// 获取不符合条件的叶子结点
													hiddenNodes = zTreeObj
															.getNodesByFilter(filterFunc);

													// 隐藏不符合条件的叶子结点
													zTreeObj
															.hideNodes(hiddenNodes);
												}
											}
											;
										}
									});
						}

						

					})
			      //查看进程信息
					.controller(
							'checkProcessController',
							function($scope, $uibModalInstance, $http, $log) {
								var basePath = $scope.getAppBasePath();
								// 程序初期化
								this.init = function() {
								}
								this.init();
								
								$scope.cancel = function() {
									// dismiss也是在模态框关闭的时候进行调用,而它返回的是一个reason
									$uibModalInstance.dismiss('cancel');
								};
							})
			//查看ip详情				
			.controller(
					'checkProcessIPController',
					function($scope, $uibModalInstance, $http, $log) {
						var basePath = $scope.getAppBasePath();
						// 程序初期化
						this.init = function() {
						}
						this.init();
						$scope.cancel = function() {
							// dismiss也是在模态框关闭的时候进行调用,而它返回的是一个reason
							$uibModalInstance.dismiss('cancel');
						};
					})				
			//新增				
			.controller(
					'insertprocessMonitorController',
					function($scope, $uibModalInstance, $http, $log) {
						var basePath = $scope.getAppBasePath();
						var controller = this;
						this.indexList = [];
						this.kpiList = [];
						// INSERT参数定义
						
						
						// 程序初期化
						this.init = function() {
					
						}
						this.init();
						
						$scope.defaultfre=function(){
							$("#selectedfre1").attr('disabled','disabled');//添加readyonly属性
							$('#selectedfre2').attr('disabled','disabled');//移除readonly属性
							$("#defaultfre").val('1')
									
						 }
						$scope.selectedfre1=function(){
							$("#defaultfre").attr('disabled',true)
						}

						$scope.save = function() {
							insertComponent = {
									"command" : "",
									"type" : "",
									"desc" : "",
									"purpose" : "",
									"hostid":"",
									"status":"",
									"alarmFrequencyId":"",
									"times":"",
									"minutes":""
							};
							
							// INSERT值获取
							insertComponent.command = $scope.$parent.insertComponent.command;
							insertComponent.desc = $scope.$parent.insertComponent.desc;
							insertComponent.purpose = $scope.$parent.insertComponent.purpose;
							insertComponent.status = $scope.$parent.insertComponent.status;
							insertComponent.alarmFrequencyId = $scope.$parent.insertComponent.alarmFrequencyId;
							insertComponent.times = $scope.$parent.insertComponent.times;
							insertComponent.minutes = $scope.$parent.insertComponent.minutes;
//							
							//提交验证
							if(insertComponent.command==''||insertComponent.command==null){
								alert("服务不能为空！");
								return
							}
							if($("#typeinput input:checked").val() == "" || $("#typeinput input:checked").val() == undefined){
								alert("类型不能为空！");
								return
							}
							if($("#defaultfre").val()== "" && (insertComponent.times== undefined || insertComponent.times=="" || insertComponent.minutes== undefined || insertComponent.minutes=="")){
								alert("请选择频率！");
								return
							}
							//获取选中的ip
				            var treeObj=$.fn.zTree.getZTreeObj("warningSelectIP");
				            selectedIp=treeObj.getCheckedNodes(true);
				            hostids=""; 
				            console.log(selectedIp);
							if(selectedIp.length==0){
								alert("请选择ip后保存！");
								return;
							}
							//获取选中ip节点
							 var emp=[];
						     var empObjList=[];
							for (var i = 0; i < selectedIp.length; i++) {
								if (selectedIp[i].chidren == undefined && selectedIp[i].isParent == false) 
								{
									console.log(selectedIp[i].id);
						                emp[i]={
						                    "command":insertComponent.command,
						                    "type":$("#typeinput input:checked").val(),
						                    "desc":insertComponent.desc,
						                    "purpose":insertComponent.purpose,
						                    "hostid":selectedIp[i].id,
						                    "status":insertComponent.status,
						                    "alarmFrequencyId":$("#defaultfre").val(),
						                    "times":insertComponent.times,
						                    "minutes":insertComponent.minutes
						                };
						                empObjList.push(emp[i]);
//									hostids+=selectedIp[i].id + ",";
								}
							}
				            
							//insertComponent.hostids = hostids;
							console.log(JSON.stringify(empObjList));
							// 后台调用
							$.ajax({
								type : "POST",
								url :  basePath+ "/data/insertProcess",
								dataType : "json",
								contentType : 'application/json;charset=utf-8',//指定为json类型 
								data : JSON.stringify(empObjList),
								success : function(data) {
									$uibModalInstance.close();
									alert("插入成功");
								}
							});
							
						};
						$scope.cancel = function() {
							// dismiss也是在模态框关闭的时候进行调用,而它返回的是一个reason
							$uibModalInstance.dismiss('cancel');
						};
					})
					//编辑配置
					.controller(
							'updateProcessController',
							function($scope, $uibModalInstance, $http, $log) {
								var basePath = $scope.getAppBasePath();
								var controller = this;
								this.indexList = [];
								this.kpiList = [];
								$scope.times="";
								$scope.minutes="";
								
								// 程序初期化
								this.init = function() {
								}
								this.init();
								$scope.defaultfre=function(){
									$("#selectedfre1").attr('disabled','disabled');//添加readyonly属性
									$('#selectedfre2').attr('disabled','disabled');//移除readonly属性
									$("#defaultfre").val('1')
											
								 }
								$scope.selectedfre1=function(){
									$("#defaultfre").attr('disabled',true)
								}
								$scope.updatesave = function() {
									// INSERT值获取
	                            if($("#defaultfre").val()== "" && ($scope.times== "" || $scope.times== undefined || $scope.minutes== ""||$scope.minutes== undefined)){
									alert("请选择频率！");
									return
								}
	                            if($scope.status== "" || $scope.status== undefined){
									alert("状态不能为空！");
									return
								}
	                            if($scope.purpose== "" || $scope.purpose== undefined){
									alert("用途不能为空！");
									return
								}
	                            if($scope.desc== "" || $scope.desc== undefined){
									alert("描述不能为空！");
									return
								}
	                                var emp=[];
	                                emp[1]={
	                    					"command":$scope.command,
	                    					"type":$scope.type,
	                    					"desc":$scope.desc,
	                    					"purpose":$scope.purpose,
	                    					"id":$scope.id,
	                    					"hostid":$scope.hostid,
	                    					"status":$scope.status,
	                    					"alarmFrequencyId":$("#defaultfre").val(),
	        								"times":$scope.times,
	        								"minutes":$scope.minutes,
	                    				};
	                    				console.log(JSON.stringify(emp[1]));
									// 后台调用
									$.ajax({
										type : "POST",
										url :  basePath+ "/data/updateProcess",
										dataType : "json",
										contentType : 'application/json;charset=utf-8',//指定为json类型 
										data :JSON.stringify(emp[1]),
										success : function(data) {
											console.log(data);
											if(data==1){
												alert("编辑成功！");
											}else{
												alert("编辑失败！");
											}
											$uibModalInstance.close();
											
										}
									});
									
								};
								$scope.cancel = function() {
									// dismiss也是在模态框关闭的时候进行调用,而它返回的是一个reason
									$uibModalInstance.dismiss('cancel');
								};
							})
					
			
})();